package com.fzu.ess.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by ercha on 2015/10/28.
 */
public class PathUtils {
    /*
        request.getSchema()返回当前页面使用的协议，http 或是 https;
        request.getServerName() 返回当前页面所在的服务器的名字;
        request.getServerPort() 返回当前页面所在的服务器使用的端口,就是80;
        request.getContextPath() 返回当前页面所在的应用的名字;
    */
    public static String getBaseUrl(){
        HttpServletRequest request =  ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        StringBuilder sb = new StringBuilder();
        sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":")
                .append(request.getServerPort()).append(request.getContextPath());
        return  sb.toString();
    }
}
